package souhu;

/**
 * Description：
 * Author: zhangc
 * Date：2017/9/17 20:07
 */

import java.util.Scanner;

public class HuiWen {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int total = scanner.nextInt();
        int[] arr = new int[ total ];
        for (int i = 0; i < total; i++) {
            arr[ i ] = scanner.nextInt();
        }
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[ i ];
        }
        System.out.println(getMax(arr, sum, 0, arr.length - 1));
    }

    public static int getMax(int[] array, int max, int low, int high) {
        if (low > high)
            return max;
        if (array[ low ] == array[ high ])
            return getMax(array, max, high - 1, low + 1);
        return Math.min(getMax(array, max + array[ high ], high - 1, low),
                getMax(array, max + array[ low ], high, low + 1));
    }
}
